package com.test.rabbitmq.handler;

import com.rabbitmq.client.ConfirmCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 用来确认生产者producer将消息发送到broker，broker上的交换机exchange再投递给队列queue的过程消息是否成功投递
 *
 */
@Slf4j
@Component
public class ConfirmCallbackService implements RabbitTemplate.ConfirmCallback {

    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if(!ack){
            log.error("消息发送异常");
            //重发
        }else{
            log.error("消息发送成功");
        }
    }
}
